package com.mornd.gulimall.member.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mornd.gulimall.member.entity.MemberLevel;
import com.mornd.gulimall.member.mapper.MemberLevelMapper;
import com.mornd.gulimall.member.service.IMemberLevelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 会员等级 服务实现类
 * </p>
 *
 * @author mornd
 * @since 2023-07-31
 */
@Service
public class MemberLevelServiceImpl extends ServiceImpl<MemberLevelMapper, MemberLevel> implements IMemberLevelService {

    @Override
    public IPage<MemberLevel> list(MemberLevel query) {
        IPage<MemberLevel> page = new Page<>(query.validPageNum(), query.validPageSize());
        super.page(page, Wrappers.<MemberLevel>lambdaQuery().eq(StringUtils.hasText(query.getName()), MemberLevel::getName, query.getName()));
        return page;
    }

    @Override
    public List<MemberLevel> filter(MemberLevel query) {
        LambdaQueryWrapper<MemberLevel> qw = Wrappers.<MemberLevel>lambdaQuery()
                .eq(query.getPriviledgeMemberPrice() != null, MemberLevel::getPriviledgeMemberPrice, query.getPriviledgeMemberPrice());
        return super.list(qw);
    }
}
